use "$temp/acs_longform_merged_clean_all", clear //
keep if dby>=1990 //restrict to at-risk sample
drop if parent_inc_quart == . & merge_long == 3 //nix matched kids with no parent income

//differnces in shocks if moved?
ren cz_shock cz_shock_2000
merge m:1 cz using "$temp/cz_shocks", keep(1 3) nogen //get CZ shocks
gen diff = cz_shock - cz_shock_2000
su diff [w=weight] if year==2007 & cz_2000!=cz & merge_long==3

//how many kids in 2000 cz?
su mig_cz [w = weight] if year == 2007 & merge_long == 3 //take 100 minus the mean to get the rate at which people in 2007 are in their year-2000 CZ
su mig_cz [w = weight] if year == 2007 & merge_long == 3 & parent_inc_quart == 1
su mig_cz [w = weight] if year == 2007 & merge_long == 3 & parent_inc_quart == 2
su mig_cz [w = weight] if year == 2007 & merge_long == 3 & parent_inc_quart == 3
su mig_cz [w = weight] if year == 2007 & merge_long == 3 & parent_inc_quart == 4
gen match_long = (merge_long == 3)

//final cleaning
replace coll = 0 if age_group == 1
replace assoc = 0 if age_group == 0
replace ti = . if wag == . 
replace wag = . if ti == . 

//linkage rates
cap log close
log using "$output/for_disclosure/output/match_rates.txt", replace
qui{
forval i = 2005 / 2018{
	su pik_match if year == `i'
	local rep1 = round(`r(mean)', 0.001)
	su match_long if year == `i'
	local rep2 = round(`r(mean)', 0.001)
	noi di "Match Rates for Year `i'"
	noi di "PIK Match Rate: `rep1' || 2000 Long-Form Match Rate: `rep2'"
	noi di ""
}
}
log close
gen male = (sex == 0)
gen white = (race == 1)
gen married = (mar == "1")
gen stfip = st
destring stfip, replace

//region dummies
merge m:1 stfip using "$data/Other/state_region_xwalk", keep(match) nogen
gen NE = (region == 1)
gen MW = (region == 2)
gen SE = (region == 3)
gen W = (region == 4)
replace wag = wag/1000

ds male white black asian hispan married NE MW SE W
foreach var in `r(varlist)'{
	replace `var' = `var' * 100 //rescaling
}

//summary statistics
eststo base: estpost su age male white black asian hispan married emp wag hrlywage coll assoc hs NE MW SE W [fw = pwgt]
eststo pik: estpost su age male white black asian hispan married emp wag hrlywage coll assoc hs NE MW SE W [fw = pwgt] if pik_match
eststo cen: estpost su age male white black asian hispan married emp wag hrlywage coll assoc hs NE MW SE W [fw = pwgt] if match_long
esttab base pik cen using "$output/for_disclosure/output/summary_stats.tex", replace cell(mean(fmt(2)) sd(par fmt(2))) //export


//end of dofile
